package com.kingdee.pda.commonmethod;

import android.content.Context;

import com.example.basecommon.http.MyObserver;
import com.example.basecommon.http.RxHelper;
import com.example.basecommon.http.rxjava.BaseResponse;
import com.example.basecommon.http.rxjava.HttpUtils;
import com.example.basecommon.utils.ConstantUtil;
import com.kingdee.pda.Api;
import com.kingdee.pda.entity.Goods;

import java.util.HashMap;

/**
 * @author：dlj
 * @data：2022/1/14
 * @des：sku校验 Presenter
 */
public class CheckSkuPresenter {

    private Context context;
    private CheckSkuView view;

    public CheckSkuPresenter(Context context, CheckSkuView queryStockView) {
        this.context = context;
        this.view = queryStockView;
    }

    //校验sku
    public void queryGoods(long warehouseId, long locationId, String barcode) {
        HashMap<String, Object> json = new HashMap<>();
        json.put("warehouseId", warehouseId);
        json.put("locationId", locationId);
        json.put("itemBarcode", barcode);
        json.put("fastFlag", locationId == 0 ? "true" : "false");//是否快速移库
        MyObserver<Goods> myObserver = new MyObserver<Goods>(context) {
            @Override
            public void onSuccess(BaseResponse<Goods> result) {
                view.queryGoodsSuccess(result.data);
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
                view.queryGoodsFailed(msg);
            }
        };
        HttpUtils.request(Api.class)
                .queryGoods(ConstantUtil.PDA_query_sku, json)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(myObserver);
    }
}
